Programming in SFC
Creating a POU in SFC
Select an application in the device tree.
Click .
The Add POU dialog opens.
Specify a name and select the Sequential Function Chart (SFC) implementation language.
Click Add.
CODESYS adds the POU to the device tree and opens it in the editor.
Adding a step-transition
Select the transition after the initial step.
The transition is marked in red.
Click .
The
Step0step and theTrans0transition are inserted.Select the
Trans0transition and click .The
Trans1transition and theStep1step are inserted before theTrans0transition.
You can also drag the Step and Transition elements into the diagram from the Toolbox view.
For more information, see: Step and Transition
Adding an entry action
Select the
Step0step.Click .
By default, you are prompted to select the duplication mode for the step actions. You decide whether the reference information about the existing step action objects is copied when the step is copied, or the objects are "embedded". Embedding results in new step action objects being created when the step is copied. The duplication mode is defined in the Duplicate when copying step property. As long as this property is disabled, the copied steps call the same actions as the current step.
You can deactivate the prompt completely in the SFC properties.
The display of "embedded" objects in the Devices and POUs views can be deactivated by means of a menu command.
For this example, accept the Copy reference default setting and click OK to confirm.
The Add Entry Action dialog opens.
Specify the name as
Step0_entryand select the Structured Text (ST) implementation language. Click Add.CODESYS inserts the
Step0_entryaction below the POU in the device tree and opens the action in the editor.In the
Step0_entryentry action, you program statements to be executed one time when theStep0step becomes active.Close the editor of
Step0_entry.The
Step0step is now marked with anEin the lower left corner. Double-click this marker to open the editor.
The entry action
Step0_entryis now available in the properties of the step in Entry action. Other actions can also be selected there as needed.Select the
Step0step. Press Ctrl+V to copy the step.The same entry actions inserted above are available In the inserted copy of the step. The new step then calls the same exact action.
Adding an exit action
Select the
Step0step.Click .
By default, you are prompted to select the duplication mode for the step actions of the step. See above for adding an entry action. Then the Insert Exit Action dialog opens.
Specify the name as
Step0_exitand select the Structured Text (ST) implementation language. Click Add.The
Step0_exitaction is inserted below the POU in the device tree and opened in the editor.In the
Step0_exitexit action, you program statements to be executed one time before theStep0step becomes inactive.Close the editor of
Step0_exit.The
Step0step is now marked with anXin the lower right corner. Double-click this marker to open the editor.
You can define the exit action in the properties of the step in Exit action. Other actions can also be selected there.
Adding an action
Double-click the
Step0step.By default, you are prompted to select the duplication mode for the step actions of the step. See above for adding an entry action. The Add Action dialog opens.
Specify the name as "Step0_active" and select the Structured Text (ST) implementation language. Click Add.
CODESYS inserts the
Step0_activeaction below the POU in the device tree and opens the action in the editor.In the
Step0_activestep action, you program statements to be executed as long as the step is active.Close the editor of
Step0_active.The
Step0step is now marked with a black triangle in the upper right corner.
You can define the action in the properties of the step in Step action. Other actions can also be selected there.
Adding an alternative branch
Select the
Step1step.Click .
The
Step2step is inserted to the right of theStep1step. The steps are connected as a parallel branch signified by two pairs of double lines.Select one of the double lines.
The double line is marked red.
Click
The branch is converted into an alternative branch. The double lines change into a single line.
You can click to convert an alternative branch into a parallel branch.
For more information, see: Branch
Adding a jump
Select the
Step2step.Click .
The
Stepjump is inserted after theStep2step.Select the
Stepjump destination.You can type the jump destination manually or select it by using the
Input Assistant. Select Step0.
For more information, see: Jump
Adding a macro
Select the
Step1step.Click .
The
Macro0macro is inserted after theStep1step.Double-click the
Macro0element.The macro opens in the implementation section of the editor. The name
Macro0is displayed in the caption.Click .
A step-transition combination is inserted.
Click .
The implementation section returns to the main diagram.
For more information, see: Macro
Adding an association
Select the
Step2step.Click .
CODESYS inserts an association to the right of the
Step2step.Click in the left field of the association to select the qualifier.
You can enter the qualifier manually or use the
Input Assistant. Select P.Click in the right field of the association to select the action.
You can type the action or select it by using the
Input Assistant .
Using the analyzation.library library to analyze expressions
The analyzation.library library allows for the analyzation of expressions. It can be used, for example, in the SFC diagram to examine the result of the flag SFCError. This flag is used to monitor timeouts in the SFC diagram.
For more information, see: Library: Analyzation